﻿<%@ WebHandler Language="C#" Class="CustomObjectItemsMaint" %>

using System;
using System.Web;
using BusinessRule.DTO;
using System.Web.SessionState;
using DatabaseAccess.DBUtility;
using System.Data.OracleClient;
using System.Data;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using BusinessRule.Business;
using BusinessRule.IBusiness;
using BusinessRule.BusinessFactory;

/**
 * Description: 自定义对象子项维护
 * Copyright (c) : 通力凯顿（北京）系统集成有限公司
 * Writer:zhunan
 * create Date:2023-01-16
 */

public class CustomObjectItemsMaint : IHttpHandler, IRequiresSessionState
{
    CurrentUserInfo m_UserInfo;
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
    public void ProcessRequest(HttpContext context)
    {
        try
        {
            var action = context.Request["action"].ToString();
            m_UserInfo = (CurrentUserInfo)context.Session["CurrentUserInfo"];
            switch (action)
            {
                case "getCustomObject":
                    getCustomObject(context);//查询自定义对象
                    break;
                case "saveItem":
                     SaveItem(context);//保存子项
                    break;
                case "deleteItem":
                    DeleteItem(context);//删除子项
                    break;
                case "getData":
                    getData(context);//查询
                    break;
                case "insertData":
                    insertData(context);//添加
                    break;
                case "updateData":
                    updateData(context);//更新
                    break;
                case "deleteData":
                    deleteData(context);//删除
                    break;
                case "toggleIsuse":
                    toggleIsuse(context);//启用/停用状态切换
                    break;
                case "getCustomItems":
                    GetCustomItems(context);//查询自定义对象子项数据
                    break;
                case "getItemsMaxSeq":
                    GetItemsMaxSeq(context);//查询自定义对象子项数据最大顺序号
                    break;
                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            var result = new uMESProcessResult();
            result.Result = false;
            result.Message = ex.Message;
            context.Response.ContentType = "text/html";
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
    }
    /// <summary>
    /// 删除子项数据
    /// </summary>
    /// <param name="context"></param>
    public void DeleteItem(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        uMESProcessResult result = new uMESProcessResult();
        result.Result = false;

        var id = context.Request["customobjectitemsid"].ToString();

        DatabaseHelper.ExecuteDataByEntity(new ExcuteEntity("CustomObjectItems", ExcuteEntity.ExcuteTypeEnum.del)
        {
            WhereFileds = new List<FieldEntity> { 
                new FieldEntity("CustomObjectItemsId", id, FieldEntity.FieldTypeEnum.Str) 
            }
        });
        
        result.Result = true;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 保存子项数据
    /// </summary>
    /// <param name="context"></param>
    public void SaveItem(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        uMESProcessResult result = new uMESProcessResult();
        result.Result = false;

        Dictionary<string, string> para = new Dictionary<string, string>();
        if (context.Request["customobjectid"] != null && !string.IsNullOrWhiteSpace ( context.Request["customobjectid"].ToString()))
        {
            para.Add("CustomObjectId", context.Request["customobjectid"].ToString());
        }
        if (context.Request["customobjectitemsid"] != null && !string.IsNullOrWhiteSpace(context.Request["customobjectitemsid"].ToString()))
        {
            para.Add("CustomObjectItemsId", context.Request["customobjectitemsid"].ToString());
        }
        if (context.Request["customobjectitemsname"] != null && !string.IsNullOrWhiteSpace (context.Request["customobjectitemsname"].ToString() ))
        {
            para.Add("ItemName", context.Request["customobjectitemsname"].ToString());
        }
        if (context.Request["customobjectitemsdesc"] != null )
        {
            para.Add("ItemDesc", context.Request["customobjectitemsdesc"].ToString());
        }
        if (context.Request["customobjectitemsnotes"] != null)
        {
            para.Add("ItemNotes", context.Request["customobjectitemsnotes"].ToString());
        }
        if (context.Request["sequence"] != null )
        {
            para.Add("Sequence", context.Request["sequence"].ToString());
        }
        if (context.Request["isuse"] != null )
        {
            para.Add("IsUse", context.Request["isuse"].ToString());
        }
        if (context.Request["factoryid"] != null )
        {
            para.Add("FactoryId", context.Request["factoryid"].ToString());
        }
        if (context.Request["type"] != null )
        {
            para.Add("Type", context.Request["type"].ToString());
        }
        
        //进行数据增加，修改 
        if (para["Type"] == "1")//添加
        {
            if(DatabaseHelper.QuerySingleDataByEntity ("1","CustomObjectItems",new List<FieldEntity>(){                
                    new FieldEntity("customobjectitemsname", para["ItemName"], FieldEntity.FieldTypeEnum.Str),
                    new FieldEntity("CustomObjectId", para["CustomObjectId"], FieldEntity.FieldTypeEnum.Str)
            }) !=null){
                result.Message = "已存在值：" + para["ItemName"]+" 不能重复添加";
                context.Response.Write(JsonConvert.SerializeObject(result));
                return;
            }
            
            var maxSeq = GetItemsMaxSeq(para["CustomObjectId"]);
            DatabaseHelper.ExecuteDataByEntity(new ExcuteEntity("CustomObjectItems", ExcuteEntity.ExcuteTypeEnum.insert)
            {
                ExcuteFileds = new List<FieldEntity> { 
                    new FieldEntity("customobjectid", para["CustomObjectId"], FieldEntity.FieldTypeEnum.Str),
                    new FieldEntity("CustomObjectItemsId", Guid.NewGuid().ToString (), FieldEntity.FieldTypeEnum.Str),
                    new FieldEntity("customobjectitemsname", para["ItemName"], FieldEntity.FieldTypeEnum.Str),
                    new FieldEntity("customobjectitemsdesc", para["ItemDesc"], FieldEntity.FieldTypeEnum.Str),
                    new FieldEntity("customobjectitemsnotes", para["ItemNotes"], FieldEntity.FieldTypeEnum.Str),
                    new FieldEntity("Sequence", maxSeq, FieldEntity.FieldTypeEnum.Numer ),
                    new FieldEntity("factoryid", para["FactoryId"], FieldEntity.FieldTypeEnum.Str),
                    new FieldEntity("createemployeeid", m_UserInfo .EmployeeID , FieldEntity.FieldTypeEnum.Str),
                    new FieldEntity("lastchangeemployeeid", m_UserInfo .EmployeeID, FieldEntity.FieldTypeEnum.Str),
                    new FieldEntity("isuse",int.Parse ( para["IsUse"]), FieldEntity.FieldTypeEnum.Numer ),
                    new FieldEntity("createdate", DateTime .Now  , FieldEntity.FieldTypeEnum.DateTime ),
                    new FieldEntity("lastchangedate",DateTime .Now, FieldEntity.FieldTypeEnum.DateTime)
                }
            });
        }else if (para["Type"] == "2"){//修改
            DatabaseHelper.ExecuteDataByEntity(new ExcuteEntity("CustomObjectItems", ExcuteEntity.ExcuteTypeEnum.update)
            {
                ExcuteFileds = new List<FieldEntity> {  
                    new FieldEntity("customobjectitemsname", para["ItemName"], FieldEntity.FieldTypeEnum.Str),
                    new FieldEntity("customobjectitemsdesc", para["ItemDesc"], FieldEntity.FieldTypeEnum.Str),
                    new FieldEntity("customobjectitemsnotes", para["ItemNotes"], FieldEntity.FieldTypeEnum.Str),
                    new FieldEntity("Sequence", int.Parse (para["Sequence"]), FieldEntity.FieldTypeEnum.Numer ),
                    new FieldEntity("factoryid", para["FactoryId"], FieldEntity.FieldTypeEnum.Str), 
                    new FieldEntity("lastchangeemployeeid", m_UserInfo .EmployeeID, FieldEntity.FieldTypeEnum.Str),
                    new FieldEntity("isuse",int.Parse ( para["IsUse"]), FieldEntity.FieldTypeEnum.Numer ), 
                    new FieldEntity("lastchangedate",DateTime .Now, FieldEntity.FieldTypeEnum.DateTime)
                },
                WhereFileds = new List<FieldEntity> { 
                    new FieldEntity("CustomObjectItemsId", para["CustomObjectItemsId"], FieldEntity.FieldTypeEnum.Str)                    
                }
            });
        }
        

        result.Result = true;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    
    //获取最大顺序号
    public void GetItemsMaxSeq(HttpContext context)
    {
        var parentId = context.Request["customobjectid"].ToString();
        var re = GetItemsMaxSeq(parentId );
        context.Response.Write(re);
    }
    
    /// <summary>
    /// 获取最大顺序号
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    int GetItemsMaxSeq(string id){
        var re = 0;
        var maxSeq = DatabaseHelper.GetSingle(string.Format(@"SELECT max(t.sequence) maxseq  FROM customobjectitems T 
where t.customobjectid='{0}' and t.sequence is not null", id));
        if (maxSeq != null)
        {
            re = int.Parse(maxSeq.ToString());
            re++;
        }
        else
        {
            re = 1;
        }
        return re;
    }

    /// <summary>
    /// 查询自定义对象子项数据
    /// add:Wangjh 2023/4/20
    /// </summary>
    /// <param name="context"></param>
    public void GetCustomItems(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        uMESProcessResult result = new uMESProcessResult();
        result.Result = false;

        Dictionary<string, string> para = new Dictionary<string,string>();
        if (context.Request["customobjectid"] != null && context.Request["customobjectid"].ToString() != "")
        {
            para.Add("CustomObjectId", context.Request["customobjectid"].ToString());
        }
        if (context.Request["customobjectitemsname"] != null && context.Request["customobjectitemsname"].ToString() != "")
        {
            para.Add("ItemName", context.Request["customobjectitemsname"].ToString());
        }
        if (context.Request["customobjectitemsdesc"] != null && context.Request["customobjectitemsdesc"].ToString() != "")
        {
            para.Add("ItemDesc", context.Request["customobjectitemsdesc"].ToString());
        }
        if (context.Request["creater"] != null && context.Request["creater"].ToString() != "")
        {
            para.Add("Creater", context.Request["creater"].ToString());
        }
        if (context.Request["createdateStart"] != null && context.Request["createdateStart"].ToString() != "")
        {
            para.Add("StartCreateDate", context.Request["createdateStart"].ToString());
        }
        if (context.Request["createdateEnd"] != null && context.Request["createdateEnd"].ToString() != "")
        {
            para.Add("EndCreateDate", context.Request["createdateEnd"].ToString());
        }
        if (context.Request["isuse"] != null && context.Request["isuse"].ToString() != "全部") {
            para.Add("IsUse", context.Request["isuse"].ToString());
        }

        string strSql = @"SELECT o.customobjectid,o.customobjectname,o.customobjectdesc,
t.customobjectitemsid,t.customobjectitemsname,t.customobjectitemsnotes,t.customobjectitemsdesc,
e.fullname creater,t.createdate,e2.fullname updater,t.lastchangedate,
t.isuse,t.factoryid,fa.factoryname,t.sequence 
FROM customobjectitems t
LEFT JOIN customobject o ON t.customobjectid = o.customobjectid
LEFT JOIN employee e ON e.employeeid = t.createemployeeid
LEFT JOIN employee e2 ON e2.employeeid = t.lastchangeemployeeid 
left join factory fa on fa.factoryid=t.factoryid
WHERE 1=1 ";
        if (para.ContainsKey("CustomObjectId"))
        {
            strSql += string.Format(" AND t.customobjectid = '{0}'", para["CustomObjectId"]);            
        }
        if (para.ContainsKey("ItemName"))
        {
            strSql += string.Format(" AND t.customobjectitemsname like '%{0}%'", para["ItemName"]);
        }
        if (para.ContainsKey("ItemDesc"))
        {
            strSql += string.Format(" AND t.customobjectitemsdesc like '%{0}%'", para["ItemDesc"]);
        }
        if (para.ContainsKey("Creater"))
        {
            strSql += string.Format(" AND e.fullname LIKE '%{0}%' ", para["Creater"]);
        }
        if (para.ContainsKey("StartCreateDate"))
        {
            strSql += string.Format(" AND t.createdate >= to_date('{0} 00:00:00','yyyy/mm/dd hh24:mi:ss') ", para["StartCreateDate"]);
        }
        if (para.ContainsKey("EndCreateDate"))
        {
            strSql += string.Format(" AND t.createdate <= to_date('{0} 23:59:59','yyyy/mm/dd hh24:mi:ss') ", para["EndCreateDate"]);
        }
        if (para.ContainsKey("IsUse"))
        {
            strSql += string.Format(" AND t.isuse={0} ", para["IsUse"]);
        }

        strSql += " order by t.sequence,t.lastchangedate ";
        uMESPagingDataDTO paraPage = new uMESPagingDataDTO();
        paraPage.CurrentPageIndex = Convert.ToInt32(context.Request.Form["pageNumber"].ToString());//页码
        paraPage.PageSize = Convert.ToInt32(context.Request.Form["PageSize"].ToString());//每页页数
        paraPage.strSQL = strSql ;
         result = DatabaseHelper.RunProcedureForPage(paraPage);

        foreach (DataColumn col in result.DBTable.Columns)
        {
            col.ColumnName = col.ColumnName.ToLower();
        }
        
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    
    //查询自定义对象
    void getCustomObject(HttpContext context)
    {
        if (m_UserInfo == null)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "当前未登录", DBTable = null }));
        }
        else
        {
            string sql = @"SELECT t.customobjectid,t.customobjectname FROM customobject t WHERE t.isuse = 0";
            DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
            foreach (DataColumn col in dt.Columns)
            {
                col.ColumnName = col.ColumnName.ToLower();
            }
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = true, Message = "获取成功", DBTable = dt }));
        }
    }

    //查询已维护数据
    void getData(HttpContext context)
    {
        if (m_UserInfo == null)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "当前未登录", DBTable = null }));
        }
        else
        {
            string sql = @"
SELECT o.customobjectid,o.customobjectname,o.customobjectdesc,
       t.customobjectitemsid,t.customobjectitemsname,t.customobjectitemsnotes,t.customobjectitemsdesc,
       e.fullname creater,t.createdate,e2.fullname updater,t.lastchangedate,
       t.isuse,SUM(DECODE(cci.containersuffixid,NULL,0,1)) useqty
FROM customobjectitems t
LEFT JOIN customobject o ON t.customobjectid = o.customobjectid
LEFT JOIN employee e ON e.employeeid = t.createemployeeid
LEFT JOIN employee e2 ON e2.employeeid = t.lastchangeemployeeid
LEFT JOIN containercurrentinfo cci ON cci.containersuffixid = t.customobjectitemsid
WHERE 1=1";
            //父对象id
            if (context.Request["customobjectid"] != null && context.Request["customobjectid"].ToString() != "")
            {
                sql += string.Format(" AND t.customobjectid = '{0}'", context.Request["customobjectid"].ToString());
            }

            //子项名称
            if (context.Request["customobjectitemsname"] != null && context.Request["customobjectitemsname"].ToString() != "")
            {
                sql += string.Format(" AND t.customobjectitemsname LIKE '%{0}%'", context.Request["customobjectitemsname"].ToString());
            }

            //创建人
            if (context.Request["creater"] != null && context.Request["creater"].ToString() != "")
            {
                sql += string.Format(" AND e.fullname LIKE '%{0}%'", context.Request["creater"].ToString());
            }

            //创建时间
            if (context.Request["createdateStart"] != null && context.Request["createdateStart"].ToString() != "")
            {
                sql += string.Format(" AND t.createdate >= to_date('{0} 00:00:00','yyyy/mm/dd hh24:mi:ss')", context.Request["createdateStart"].ToString());
            }
            if (context.Request["createdateEnd"] != null && context.Request["createdateEnd"].ToString() != "")
            {
                sql += string.Format(" AND t.createdate <= to_date('{0} 23:59:59','yyyy/mm/dd hh24:mi:ss')", context.Request["createdateEnd"].ToString());
            }

            //启用状态
            if (context.Request["isuse"] != null && context.Request["isuse"].ToString() != "全部")
            {
                sql += string.Format(" AND t.isuse = '{0}'", context.Request["isuse"].ToString());
            }

            sql += @"
GROUP BY o.customobjectid,o.customobjectname,o.customobjectdesc,
         t.customobjectitemsid,t.customobjectitemsname,t.customobjectitemsnotes,t.customobjectitemsdesc,
         e.fullname,t.createdate,e2.fullname,t.lastchangedate,
         t.isuse
";
            uMESPagingDataDTO paraPage = new uMESPagingDataDTO();
            paraPage.CurrentPageIndex = Convert.ToInt32(context.Request.Form["pageNumber"].ToString());//页码
            paraPage.PageSize = Convert.ToInt32(context.Request.Form["PageSize"].ToString());//每页页数
            paraPage.strSQL = sql;
            uMESProcessResult result = DatabaseHelper.RunProcedureForPage(paraPage);
            foreach (DataColumn col in result.DBTable.Columns)
            {
                col.ColumnName = col.ColumnName.ToLower();
            }
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
    }

    //插入
    void insertData(HttpContext context)
    {
        if (m_UserInfo == null)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "当前未登录", DBTable = null }));
        }
        else
        {
            string customObjectId = context.Request.Form["customObjectId"].ToString();//父对象id
            string customObjectName = context.Request.Form["customObjectName"].ToString();//父对象名称
            string customObjectItemsName = context.Request.Form["customObjectItemsName"].ToString();//子项名称
            string sql = string.Format("select * from customobjectitems t where t.customobjectitemsname = '{0}' AND t.customobjectid = '{1}'", customObjectItemsName, customObjectId);
            DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
            if (dt.Rows.Count > 0)
            {
                context.Response.Write(
                    JsonConvert.SerializeObject(
                        new uMESProcessResult()
                        {
                            Result = false,
                            Message = "父项【" + customObjectName + "】中已存在子项【" + customObjectItemsName + "】!",
                            DBTable = null
                        }
                    )
                );
            }
            else
            {
                string customObjectItemsDesc = context.Request.Form["customObjectItemsDesc"].ToString();//子项描述
                string customObjectItemsNotes = context.Request.Form["customObjectItemsNotes"].ToString();//子项描述
                string isuse = context.Request.Form["isuse"].ToString();//启用状态
                string createemployeeid = m_UserInfo.EmployeeID.ToString();//创建人
                sql = @"
INSERT INTO customobjectitems(customobjectitemsid,customobjectid,customobjectitemsname,customobjectitemsdesc,customobjectitemsnotes,createemployeeid,createdate,isuse)
VALUES('{0}','{1}','{2}','{3}','{4}','{5}',sysdate,'{6}')";

                sql = string.Format(sql, Guid.NewGuid().ToString(),//唯一id
                                         customObjectId,//父对象id
                                         customObjectItemsName,//子项名称
                                         customObjectItemsDesc,//子项描述
                                         customObjectItemsNotes,//备注
                                         createemployeeid,//创建人
                                         isuse);
                int insertResult = DatabaseHelper.ExecuteSql(sql);
                context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = true, Message = "", DBTable = null }));
            }
        }
    }

    //更新
    void updateData(HttpContext context)
    {
        if (m_UserInfo == null)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "当前未登录", DBTable = null }));
        }
        else
        {
            string customobjectitemsid = context.Request.Form["customobjectitemsid"].ToString();//后缀标识id
            string customobjectitemsname = context.Request.Form["customobjectitemsname"].ToString();//后缀标识
            string customobjectitemsdesc = context.Request.Form["customobjectitemsdesc"].ToString();//后缀描述
            string customobjectitemsnotes = context.Request.Form["customobjectitemsnotes"].ToString();//备注
            string customobjectid = context.Request.Form["customobjectid"].ToString();//父对象id
            string customobjectname = context.Request.Form["customobjectname"].ToString();//父对象名称

            string lastchangeemployeeid = m_UserInfo.EmployeeID.ToString();//更新人
            string sql = string.Format("SELECT t.customobjectitemsname FROM customobjectitems t WHERE t.customobjectid = '{0}' AND t.customobjectitemsid = '{1}'",
                                        customobjectid, customobjectitemsid);
            DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
            if (dt.Rows[0]["customobjectitemsname"].ToString() == customobjectitemsname)//将要修改的对象名称和原来保持一致时
            {
                sql = @"
UPDATE customobjectitems t SET t.customobjectitemsdesc = '{0}',t.customobjectitemsnotes = '{1}',t.lastchangeemployeeid='{2}',t.lastchangedate = SYSDATE WHERE t.customobjectitemsid = '{3}'";
                sql = string.Format(sql, customobjectitemsdesc,//后缀描述
                                         customobjectitemsnotes,//备注
                                         lastchangeemployeeid,//更新人
                                         customobjectitemsid);//后缀唯一id
                int insertResult = DatabaseHelper.ExecuteSql(sql);
                context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = true, Message = "", DBTable = null }));
            }
            else
            {
                sql = string.Format("SELECT t.customobjectitemsname FROM customobjectitems t WHERE t.customobjectid = '{0}' AND t.customobjectitemsname = '{1}'",
                                    customobjectid, customobjectitemsname);
                dt = DatabaseHelper.Query_ReturnDatTable(sql);
                if (dt.Rows.Count > 0)//将要修改后的对象名称已存在时
                {
                    context.Response.Write(
                        JsonConvert.SerializeObject(
                            new uMESProcessResult()
                            {
                                Result = false,
                                Message = "更新失败，父对象【" + customobjectname + "】中已存在后缀名称【" + customobjectitemsname + "】!",
                                DBTable = null
                            }
                        )
                    );
                }
                else
                {
                    sql = @"
UPDATE customobjectitems t SET t.customobjectitemsname = '{0}',t.customobjectitemsdesc = '{1}',t.customobjectitemsnotes = '{2}',t.lastchangeemployeeid='{3}',t.lastchangedate = SYSDATE 
WHERE t.customobjectitemsid = '{4}'";
                    sql = string.Format(sql, customobjectitemsname,//后缀名称
                                             customobjectitemsdesc,//后缀描述
                                             customobjectitemsnotes,//备注
                                             lastchangeemployeeid,//更新人
                                             customobjectitemsid);//后缀唯一id
                    int insertResult = DatabaseHelper.ExecuteSql(sql);
                    context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = true, Message = "", DBTable = null }));
                }
            }
        }
    }

    //删除
    void deleteData(HttpContext context)
    {
        if (m_UserInfo == null)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "当前未登录", DBTable = null }));
        }
        else
        {
            DataTable dtPostData = JsonConvert.DeserializeObject<DataTable>(context.Request.Form["willBeDeleteData"].ToString());
            foreach (DataRow dr in dtPostData.Rows)
            {
                string sql = @"
SELECT cci.containerid 
FROM customobjectitems t
INNER JOIN containercurrentinfo cci ON cci.containersuffixid = t.customobjectitemsid
WHERE t.customobjectitemsid = '{0}' ";
                sql = string.Format(sql, dr["customobjectitemsid"].ToString());
                DataTable dt = DatabaseHelper.Query_ReturnDatTable(sql);
                if (dt.Rows.Count > 0)
                {
                    context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "删除失败，有批次正在使用，不能删除!", DBTable = null }));
                }
                else
                {
                    sql = string.Format("DELETE customobjectitems t WHERE t.customobjectitemsid = '{0}'", dr["customobjectitemsid"].ToString());
                    int insertResult = DatabaseHelper.ExecuteSql(sql);
                    context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = true, Message = "", DBTable = null }));
                }
            }
        }
    }

    //停用/启用切换
    void toggleIsuse(HttpContext context)
    {
        if (m_UserInfo == null)
        {
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = false, Message = "当前未登录", DBTable = null }));
        }
        else
        {
            DataTable dtPostData = JsonConvert.DeserializeObject<DataTable>(context.Request.Form["selectData"].ToString());
            string sql = "";
            foreach (DataRow dr in dtPostData.Rows)
            {
                sql = string.Format("UPDATE customobjectitems t SET t.isuse = DECODE(t.isuse,0,1,1,0) WHERE t.customobjectitemsid = '{0}'", dr["customobjectitemsid"].ToString());
                int insertResult = DatabaseHelper.ExecuteSql(sql);
            }
            context.Response.Write(JsonConvert.SerializeObject(new uMESProcessResult() { Result = true, Message = "", DBTable = null }));
        }
    }
}